import dt from '@dt/dt'
import clueCustomerMgr from '@/biz/customer/clueCustomer.js'
import dateOpt from '@/biz/option/date.js'
import CustomerMgr from '@/biz/customer/customerOpt.js';
let _this = null
let acquisitionMethodOption = [
  { key: 1, value: '客户授权' },
  { key: 2, value: '客户来电' },
  { key: 3, value: '手动分配' },
  { key: 4, value: '场外报备' },
  { key: 5, value: '手动录入' },
]

let customerStatusList = [
  { key: 1, value: '线索客户' },
  { key: 2, value: '到访客户' },
  { key: 3, value: '成交客户' },
]

// let customerStatusList = [
//   { key: 18258, value: '首访' },
//   { key: 18259, value: '回笼' },
//   { key: 18263, value: '认购' },
//   { key: 18264, value: '签约' },
//   { key: 18265, value: '全款' },
//   { key: 18266, value: '交房' },
// ]


function options(vm, head) {
  _this = vm
  return [
    {
      type: 'checkbox',
      width: 60,
      align: 'center',
      fixed: 'left',
      // showOverflow: false,
      // cell: {
      //   value: (row) => {
      //     return row.newUserId != row.userId ?
      //       '该客户的“现归属顾问”已变更，与分配记录不同，不可重新分配' : row.hereto != 1 ? "该客户已到访本案场（已到访），不可重新分配" :
      //       '2'
      //   },
      //   text: {
      //     placement: 'right',
      //     width: '40px',
      //     position: 'relative',
      //     height: '20px',
      //     left: '-10px',
      //     opacity: 0
      //   }
      // },
    },
    {
      field: 'customerName',
      title: '客户姓名',
      minWidth: 200,
      fixed: 'left',
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {}
        }
      },
    },
    {
      field: 'customerPhone',
      minWidth: 130,
      fixed: 'left',
      header: {
        filter: {
          title: '手机号码',
          key: 'customerPhone',
          placeholder: '请输入手机号码',
          input: {}
        }
      }
    },

    {
      field: 'userName',
      minWidth: 120,
      header: {
        filter: {
          title: '原归属顾问',
          key: 'userIds',
          placeholder: '请选择原归属顾问',
          load: (o) => {
            o.select.options = clueCustomerMgr.consultants1()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
            remote: (key) => {
              return clueCustomerMgr.selectTeamUser(key)
            }
          }
        },

      },
    },


    {
      field: 'channelName',
      minWidth: 160,
      header: {
        filter: {
          title: '渠道',
          key: 'channelSource',
          placeholder: '请选择渠道',
          load: (o) => {
            o.select.options = clueCustomerMgr.channelSource()
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'customerStatus',
      minWidth: 120,
      header: {
        filter: {
          title: '客户进度',
          key: 'customerStatusList',
          placeholder: '请选择客户进度',
          load: (o) => {
            o.select.options = customerStatusList
          },
          select: {
            options: [],
            multiple: true,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'intentionLevel',
      minWidth: 120,
      header: {
        filter: {
          title: '意向等级',
          key: 'intentionLevel',
          placeholder: '请选择意向等级',
          load: (o) => {
            o.select.options = CustomerMgr.intentionLevel()
          },
          select: {
            options: [],
            multiple: false,
            filterable: true,
          }
        }
      }
    },
    {
      field: 'reason',
      minWidth: 120,
      header: {
        filter: {
          title: '进池原因',
          key: 'reasons',
          placeholder: '请选择进池原因',
          // load: (o) => {
          //   o.select.options = CustomerMgr.intentionLevel()
          // },
          select: {
            options: [{
              key: 1,
              value: '无效客户'
            }, {
              key: 2,
              value: '顾问离案'
            }],
            multiple: true,
            filterable: true,
          }
        }
      }
    },

    {
      title: '入池时间',
      field: 'createTime',
      minWidth: 180,

      header: {
        filter: dateOpt.range({
          title: '入池时间',
          placeholder: '请选择入池时间',
          startKey: 'poolStartTime',
          endKey: 'poolEndTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.poolStartTime, val
                .poolEndTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.poolStartTime, val
              .poolEndTime).Y >= 2)
          }
        }),
      },
    },
    {
      title: '最新跟进时间',
      field: 'lastFollowUpTime',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '最新跟进时间',
          placeholder: '请选择最新跟进时间',
          startKey: 'lastFollowUpStartTime',
          endKey: 'lastFollowUpEndTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.lastFollowUpStartTime, val
                .lastFollowUpEndTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('认购日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.lastFollowUpStartTime, val
              .lastFollowUpEndTime).Y >= 2)
          }
        }),
      },
    },
    {
      title: '最新跟进记录',
      field: 'lastFollowUp',
      minWidth: 120,
    },
    {
      field: 'handles',
      title: '操作',
      width: 150,
      fixed: 'right',
      align: 'center',
      className: 'conciseContent',
      slots: {
        default: (params, h) => {
          return [h(
            'div', {
              style: {
                display: 'flex',
                flexDirection: 'column',
              },
            },
            [
              h(
                'Button', {
                  props: {
                    type: 'text',
                  },
                  style: {
                    cursor: 'pointer',
                    padding: '0 5px',
                    color: '#0F42A7'
                  },
                  on: {
                    click: (e) => {
                      e.stopPropagation()
                      _this.viewClick(params.row)
                    },
                  },
                },
                '查看详情'
              ),

            ]
          )]
        }
      }
    }
  ]
}

export default {
  options
}